package core;

/**
 *
 * @author Oscar
 *
 *A Player class, consisting of the personal status and parameters for a Player in the game.
 */

import gui.HandViewPanel;

import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

import card.Card;

public class Player extends Observable {

	Point startPosition;
	/** Cards that are ready to be drawn **/
	public List<Card> deck=new ArrayList<Card>();
	public List<Card> discardPile=new ArrayList<Card>();
	public List<Card> hand=new ArrayList<Card>();

	private int gold = Constants.STARTGOLD;
	private int mana;
	private String tileImageName;
	private String name;
	private int handSize = 7;

	public int getHandSize() {
		return handSize;
	}

	public void setHandSize(int handSize) {
		this.handSize = handSize;
	}

	/**
	 * A personal id for this Player object.
	 */
	private int playerId;

	private Color playerColor;

	public Player(int id){
		this.addObserver(HandViewPanel.getInstance());
		playerId = id;
		if(id==0){
			playerColor = Color.red;
			tileImageName="tile_red.png";
			name = "Red";
		}
		else if (id==1){
			playerColor = Color.blue;
			tileImageName="tile_blue.png";
			name = "Blue";
		}
		else if (id==2){
			playerColor = new Color(220, 220, 20);
			tileImageName="tile_yellow.png";
			name = "Yellow";
		}
		else if (id==3){
			playerColor = Color.green;
			tileImageName="tile_green.png";
			name = "Green";
		}
		else {
			playerColor = Color.black;
			tileImageName="tile_black.png";
			name = "Black";
		}
	}

	public String getTileImageName(){
		return tileImageName;
	}

	public int getPlayerId(){
		return playerId;
	}

	public Color getColor(){
		return playerColor;
	}

	public String getName(){
		return name;
	}
	public void addGold(int g){
		gold = gold + g;
	}
	public void substractGold(int g){
		gold = gold - g;
	}

	public void setMana(int m){
		this.mana= m;
	}
	public void addMana(int m){
		mana = mana + m;
	}
	public void substractMana(int m){
		mana = mana - m;
	}

	public int getGold(){
		return gold;
	}

	public int getMana(){
		return mana;
	}

	public Point getStartPos(){
		return startPosition;
	}

	public List<Card> getHand(){
		return hand;
	}
	
	public List<Card> getDiscardPile(){
		return discardPile;
	}

	public List<Card> getDeck(){
		return deck;
	}

	/**
	 * Draws the first card in the deck to the hand.
	 */
	public void drawCard(){
		hand.add(deck.get(0));
		deck.remove(0);
		HandViewPanel.getInstance().repaint();
	}

	/**
	 * Remove a card from the hand.
	 * @param c
	 */
	public void removeCardFromHand(Card c){
		//System.out.println(c.getName());
		hand.remove(c);
		broadcast();
	}

	public void broadcast(){
		this.setChanged();
		this.notifyObservers();
	}

	/**
	 * Recognizes the deck as the Player's, and sets ownership of all cards in the deck to the Player.
	 * @param d
	 */
	public void setDeck(List<Card> d){
		deck = d;
		for(Card c : deck){
			c.setOwner(this);
		}
	}


}
